// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const itemTypeRequest = {
    // dict请求的基本url
    BASE_URL : confing.MD_URL + "/itemType",
	/**
	 * 搜索框根据分类名和是否启用搜索单条分类
	 * @param {Object} mdItemType
	 * @param {Object} callback
	 */
	search(mdItemType,callback){
		let url = this.BASE_URL + "/search?itemTypeName="+mdItemType.itemTypeName;
		if(mdItemType.enableFlag ){
			url+="&enableFlag="+mdItemType.enableFlag;
		}
		request.get(url,callback);
	},
	delete(itemTypeId,callback){
		let url = this.BASE_URL + "/delete?itemTypeId="+itemTypeId;
		request.delete(url,callback);
	},
	save(mdItemType,callback){
		let url = this.BASE_URL + "/save";
		if(mdItemType != undefined){
			request.post(url,mdItemType,callback);
		}
	},
	edit(mdItemType,callback){
		let url = this.BASE_URL + "/update";
		if(mdItemType != undefined && mdItemType.itemTypeId != undefined){
			request.put(url,mdItemType,callback);
		}
	},
	selectById(itemTypeId,callback){
		let url = this.BASE_URL + "/get?itemTypeId=" + itemTypeId;
		request.get(url,callback);
	},
	/**
	 * 加载所有分类
	 * @param {Object} callback
	 */
	getAllItemTypes(callback){
		let url = this.BASE_URL + "/list";
		request.get(url,callback);
	}
}
// 将dictRequest暴漏出去
export default itemTypeRequest;